package com.example.controller;

import com.example.entity.MailRequestVo;
import com.example.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author wangJinLong
 * Date 2025/11/19 18:39
 **/
@Slf4j
@RestController
@RequestMapping("/mail")
public class MailController {

    @Autowired
    private MailService mailService;

    @PostMapping("/send")
    public String sendMail(@Validated @RequestBody MailRequestVo mailRequestVo) {
        log.info("收到发送邮件请求：\n" + mailRequestVo.toString());
        try {
            mailService.sendMail(mailRequestVo);
        } catch (Exception e) {
            e.printStackTrace();
            return "邮件发送失败";
        }
        return "邮件发送成功";
    }
}
